package entity;

import type.ContainerTypeEnum;
import type.VariableTypeEnum;

import java.util.Arrays;

/**
 * 实体：【方法局部变量】/【方法参数】，只允许 final 修饰符
 *
 * @author Tao Lu
 */
public class VariableEntity extends BaseEntity {

    private String name;
    private boolean isFinal;
    private VariableTypeEnum variableTypeEnum;    // 基本数据类型 or 一般引用类型 or 类型变量（特殊引用类型）
    private Object originClass;    // 变量类型：类 or 泛型 or 具体基元类型
    private ContainerTypeEnum containerType;    // ARRAY, COLLECTION, MAP, CUSTOM, NOT
    private VariableEntity[] containerItems; // 容器元素类型 Collection & Map

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public boolean isFinal() {
        return isFinal;
    }

    public void setFinal(boolean aFinal) {
        isFinal = aFinal;
    }

    public VariableTypeEnum getVariableTypeEnum() {
        return variableTypeEnum;
    }

    public void setVariableTypeEnum(VariableTypeEnum variableTypeEnum) {
        this.variableTypeEnum = variableTypeEnum;
    }

    public Object getOriginClass() {
        return originClass;
    }

    public void setOriginClass(Object originClass) {
        this.originClass = originClass;
    }

    public ContainerTypeEnum getContainerType() {
        return containerType;
    }

    public void setContainerType(ContainerTypeEnum containerType) {
        this.containerType = containerType;
    }

    public VariableEntity[] getContainerItems() {
        return containerItems;
    }

    public void setContainerItems(VariableEntity[] containerItems) {
        this.containerItems = containerItems;
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("VariableEntity{\n\t");
        sb.append(super.toString());
        sb.append("\n\t\"name\":\"")
                .append(name).append('\"');
        sb.append(",\n\t\"isFinal\":")
                .append(isFinal);
        sb.append(",\n\t\"variableTypeEnum\":")
                .append(variableTypeEnum);
        sb.append(",\n\t\"originClass\":")
                .append(originClass);
        sb.append(",\n\t\"containerType\":")
                .append(containerType);
        sb.append(",\n\t\"containerItems\":")
                .append(Arrays.toString(containerItems));
        sb.append("\n}");
        return sb.toString();
    }
}
